package com.smartao.base.entityselector;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.smartao.base.entityitem.Entityitem;
import com.smartao.base.entityitem.EntityitemService;
import com.smartao.core.mvc.BaseAction;

@Controller
@Scope("prototype")
@Results({
	@Result(name=BaseAction.SUCCESS, type="redirect",location="${entityitem.target}"),
	@Result(name=BaseAction.ERROR, location="default.jsp")})
public class SelectorAction extends BaseAction {

	private static final long serialVersionUID = -5431131738114276797L;
	
	@Autowired
	private EntityitemService entityitemService;
	
	private Entityitem entityitem;
	
	private String entityKey;
	
	private String selectedIds;
	
	@Override
	public String execute(){
		entityitem = entityitemService.findByEntityKey(entityKey);
		if(entityitem!=null){
			return SUCCESS;
		}
		return ERROR;
	}

	public Entityitem getEntityitem() {
		return entityitem;
	}

	public void setEntityitem(Entityitem entityitem) {
		this.entityitem = entityitem;
	}

	public String getEntityKey() {
		return entityKey;
	}

	public void setEntityKey(String entityKey) {
		this.entityKey = entityKey;
	}

	public String getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String selectedIds) {
		this.selectedIds = selectedIds;
	}

}
